AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

function ENT:Initialize()
	self.Entity:SetModel("models/Items/BoxMRounds.mdl") 
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	self.Entity:SetCollisionGroup(COLLISION_GROUP_NPC)
	local phys = self.Entity:GetPhysicsObject()

	if phys and phys:IsValid() then
		phys:Wake()
	end
end

function ENT:SpawnFunction( ply, tr )
    if ( !tr.Hit ) then return end
	
    local ent = ents.Create("upgr_ammo_buckshot")
    ent:SetPos( tr.HitPos + tr.HitNormal * 16 ) 
    ent:Spawn()
    ent:Activate()
 
    return ent
end

function ENT:OnTakeDamage(dmginfo)
	self.Entity:GetPhysicsObject():AddVelocity(dmginfo:GetDamageForce() * 0.1)
end

function ENT:Use(activator, caller)
	if activator:IsPlayer() then
		if CurTime() > activator:GetActiveWeapon().ReloadDelay then
			if activator:GetActiveWeapon():GetClass():find("^cstm_shotgun_") then
				if activator:GetActiveWeapon():GetDTInt(2) == 6 then
					activator:GetActiveWeapon():SetDTInt(2, 0)
					activator:GetActiveWeapon().Primary.NumShots = 12
					activator:GetActiveWeapon().Primary.Damage = activator:GetActiveWeapon().Primary.Damage / 10
					activator:GetActiveWeapon().IronsightsCone = activator:GetActiveWeapon().IronsightsCone / 0.05
					activator:GetActiveWeapon().ScopeCone = activator:GetActiveWeapon().ScopeCone / 0.05
					umsg.Start("NBUL", activator)
						umsg.Short(12)
					umsg.End()
					
					self.Entity:Remove()
				end
			end
		end
	end
end

function ENT:OnRemove()
return false
end 